/**
 *
 * @author tzp
 * @since 2021/11/8
 */
object matchTest {
  def main(args: Array[String]): Unit = {
    val email = "(.*)@(.*)".r
    val x = new Dog("ha")
    x match {
      case _ =>
    }

    patmat(x)
    patmat(Cat("catty"))
    patmat(List("a", "b"))
    patmat(List(List(1, 2, "YAY")))
  }

  def patmat: Any => Unit = {
    case e: Dog => {
      println("find a dog")
    }
    //case Dog(n) => {} //不同类没法这样写
    case Cat(n) => println(s"find a cat $n")
    case List(l@List(1, 2, "YAY")) => println("got a list " + l.toString()) //匹配列表 且绑定变量
    case _ =>
  }
}

class Dog(name: String)

case class Cat(name: String)